﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;

namespace WXYW
{
    public partial class UsersApplicationForms : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindForms();
            }
        }

        private void BindForms()
        {
            ApplicationService appservice = new ApplicationService();
            myApplicationGridView.DataSource = appservice.GetApplicationFormsByUserID(long.Parse(Request.QueryString[Constants.QUERYSTR_USER_ID]));
            myApplicationGridView.DataBind();
            UserService userservice = new UserService();
            userNameLabel.Text = userservice.GetUserByID(long.Parse(Request.QueryString[Constants.QUERYSTR_USER_ID])).UserName;
        }

        protected void myApplicationGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            if (e.NewPageIndex >= 0 && e.NewPageIndex < myApplicationGridView.PageCount)
            {
                myApplicationGridView.PageIndex = e.NewPageIndex;
            }
            
            BindForms();
        }

        protected void viewLinkButton_click(object sender, EventArgs e)
        {
            LinkButton lnkBtn = sender as LinkButton;
            string back_url = Request.Url.ToString();
            string url = string.Format("ApplicationListProductDetail.aspx?APPLICATIOM_ID={0}&" + Constants.QUERYSTR_BACK_URL + "={1}",
                lnkBtn.CommandArgument, back_url);
            Response.Redirect(url);
        }
    }
}
